$(function() {
    var settings = {
        url: ctx + "student/list",
        pageSize: 10,
        queryParams: function(params) {
            return {
                pageSize: params.limit,
                pageNum: params.offset / params.limit + 1,
                studentId: $(".student-table-form").find("input[name='studentId']").val(),
                sonUserName: $(".student-table-form").find("input[name='sonUserName']").val(),
                userName: $('#user_name').text()
            };
        },
        columns: [{
                checkbox: true
            }, {
                field: 'id',
                visible: false
            }, {
                field: 'studentId',
                title: '考生号'
            }, {
                field: 'name',
                title: '姓名'
            }, {
                field: 'graduateAdd',
                title: '毕业高中'
            },  {
                field: 'note',
                title: '备注'
            },{
                field: 'userName',
                title: '操作人'
            }, {
                field: 'updatedTime',
                title: '最后修改时间'
            }

        ]
    }
    $MB.initTable('studentTable', settings);
});

function search() {
    $MB.refreshTable('studentTable');
}

function refresh() {
    $(".student-table-form")[0].reset();
    $MB.refreshTable('studentTable');
}

function deleteStudents() {
    var selected = $("#studentTable").bootstrapTable('getSelections');
    var selected_length = selected.length;
    var contain = false;
    if (!selected_length) {
        $MB.n_warning('请勾选需要删除的用户！');
        return;
    }
    var ids = "";
    for (var i = 0; i < selected_length; i++) {
        ids += selected[i].id;
        if (i != (selected_length - 1)) ids += ",";
        if (name == selected[i].name) contain = true;
    }
    if (contain) {
        $MB.n_warning('勾选用户中包含当前登录用户，无法删除！');
        return;
    }

    $MB.confirm({
        text: "确定删除选中考生？",
        confirmButtonText: "确定删除"
    }, function() {
        $.post(ctx + 'student/delete', { "ids": ids }, function(r) {
            if (r.code == 0) {
                $MB.n_success(r.msg);
                refresh();
            } else {
                $MB.n_danger(r.msg);
            }
        });
    });
}

var params = {
            studentId: $(".student-table-form").find("input[name='studentId']").val(),
            sonUserName: $(".student-table-form").find("input[name='sonUserName']").val(),
            status: $(".student-table-form").find("select[name='status']").val(),
            userName: $('#user_name').text()
    }
function exportStudentExcel(){
	$.post(ctx+"student/excel",params,function(r){
		if (r.code == 0) {
			window.location.href = "common/download?fileName=" + r.msg + "&delete=" + true;
		} else {
			$MB.n_warning(r.msg);
		}
	});
}
